package com.fly.core.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * CleanLogJob
 * 
 * @author 00fly
 * @version [版本号, 2022年11月30日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Slf4j
@Component
public class CleanLogJob
{
    @Autowired
    JdbcTemplate jdbcTemplate;
    
    /**
     * 7-23点每10秒执行<br>
     * 
     */
    @Scheduled(cron = "0/10 * 7-23 * * ?")
    public void run()
    {
        long count = jdbcTemplate.queryForObject("select count(*) from syslog", Long.class);
        log.info("------------------- syslog count: {} -------------------", count);
        if (count > 100)
        {
            log.info("########## delete table syslog #########");
            jdbcTemplate.execute("delete from syslog");
        }
    }
}
